<?php defined('SYSPATH') or die('No direct script access.');

class Model_Services_Report extends Model{
	
	public $report = NULL;
		
	public function __construct($report_id=false){
		if ($report_id) $this->report = $this->get($report_id);
	}
	
	public function newReport(){
		$newReport = ORM::factory("dao_report");
		$newReport->comment_aod = "";
		$newReport->comment_aos = "";
		$newReport->comment_iar = "";
		$newReport->comments = "";
		$newReport->conclusion = "";
		$newReport->habits_Summary = "";
		$newReport->background_family = "";
		$newReport->background_medicines = "";
		$newReport->background_pathologies = "";
		$newReport->background_surgeries = "";
		return $this->report = $newReport;
	}
	
	public function get($id=false){
		if ($id) return ORM::factory("dao_report")->find($id);
		return $this->report;
	}
	
	public function getAODComment(){ return ($this->report)? $this->report->comment_aod: NULL;}
	public function getAOSComment(){ return ($this->report)? $this->report->comment_aos: NULL;}
	public function getIARComment(){ return ($this->report)? $this->report->comment_iar: NULL;}
	public function getComments(){ return ($this->report)? $this->report->comments: NULL;}
	public function getConclusion(){ return ($this->report)? $this->report->conclusion: NULL;}
	public function getHabitsSummary(){return ($this->report)? $this->report->habits_Summary: NULL;}
	public function getBackgroundFamily(){return ($this->report)? $this->report->background_family: NULL;}
	public function getBackgroundMedicines(){return ($this->report)? $this->report->background_medicines: NULL;}
	public function getBackgroundPathologies(){return ($this->report)? $this->report->background_pathologies: NULL;}
	public function getBackgroundSurgeries(){return ($this->report)? $this->report->background_surgeries: NULL;}
	
	public function saveComments($content){
		$this->report->comments = $content;
		return $this->report->save();
	}
	
	public function saveConclusion($content){
		$this->report->conclusion = $content;
		return $this->report->save();
	}
	
	//Para ser utilizado por el webservice
	public function save($id, array $data){
				
		$this->report = ($id > 0) ? ORM::factory("dao_report",$id) : ORM::factory("dao_report");
		$this->report->comment_aod = $data['comment_aod'];
		$this->report->comment_aos = $data['comment_aos'];
		$this->report->comment_iar = $data['comment_iar'];
		$this->report->comments = $data['comments'];
		$this->report->conclusion = $data['conclusion'];
		$this->report->habits_Summary = $data['habits_Summary'];
		$this->report->background_family = $data['background_family'];
		$this->report->background_medicines = $data['background_medicines'];
		$this->report->background_pathologies = $data['background_pathologies'];
		$this->report->background_surgeries = $data['background_surgeries'];
				
		$this->report->save();
				
		return "Reporte: ".$this->report->id." guardado con exito";
	}
	
	public function delete($id){
		$this->report = ORM::factory("dao_report",$id);
		$this->report->delete();
		return "Registro: ".$id." eliminado con exito";
	}
	
	
}
?>